from django.shortcuts import render
from rest_framework.views import APIView
from rest_framework.response import Response
from .models import *
from .ser import *

# Create your views here.
class LoginView(APIView):
    def post(self,request):
        username = request.data.get('username')
        user = User.objects.filter(username=username).first()
        if user:
            return Response({'msg':'登陆成功','uid':user.id,'username':user.username})
        return Response({'msg':'登陆失败'})

class GoodsView(APIView):
    def get(self,request):
        queryset = Goods.objects.all()
        ser = GoodsSer(queryset,many=True)
        return Response(ser.data)